


<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>人类高质量管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">

  <!--清除缓存-->
  <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Expires" content="0">

  <link rel="stylesheet" href="layui/css/layui.css" >
  <style>
    /* 移动端 */
    @media screen and (max-width: 768px) {
      .layui-layout-admin .layui-layout-left,
      .layui-layout-admin .layui-body,
      .layui-layout-admin .layui-footer{left: 0;}
      .layui-layout-admin .layui-side{left: -300px;}
    }
  </style>
</head>
<body>

<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">宇宙级管理系统</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <!-- 移动端显示 -->
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
        <i class="layui-icon layui-icon-spread-left"></i>
      </li>

      <li class="layui-nav-item layui-hide-xs"><a href="">Windows</a></li>
      <li class="layui-nav-item layui-hide-xs"><a href="">Linux</a></li>
      <li class="layui-nav-item layui-hide-xs"><a href="">IOS</a></li>



    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
        <a href="javascript:;">
          <img src="img/icon.JPG" class="layui-nav-img">
          <span id="show_username">tester</span>
        </a>
        <dl class="layui-nav-child">
          <dd><a href="/about.html">个人信息</a></dd>
          <dd><a href="/logout">退出</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
  </div>

  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">用户</a>
          <dl class="layui-nav-child">
            <dd><a href="user.html">用户管理</a></dd>
            <dd><a href="usergroup.html">用户分组</a></dd>
            <dd><a href="javascript:;">用户标签</a></dd>

          </dl>
        </li>
        <li class="layui-nav-item layui-nav-itemed">
          <a href="javascript:;">商品</a>
          <dl class="layui-nav-child">
            <dd><a href="goods.html">商品管理</a></dd>
            <dd><a href="javascript:;">商品分组</a></dd>
            <dd><a href="javascript:;">商品统计</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item layui-nav-itemed">
          <a href="javascript:;">客服</a>
          <dl class="layui-nav-child">
            <dd   class="layui-this"><a href="cs.html">客服管理</a></dd>
            <dd><a href="javascript:;">客服分组</a></dd>
            <dd><a href="javascript:;">客服话术</a></dd>
          </dl>
        </li>
      </ul>
    </div>
  </div>

  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">

      <!-- 内容主体区域  面包屑-->
      <span class="layui-breadcrumb">
        <a href="index.html">首页</a>
        <a><cite>客服</cite></a>
        <a><cite>客服管理</cite></a>
      </span>

      <!-- 水平线 -->
      <hr class="layui-bg-blue">


      <!-- 搜索条件 -->
      <fieldset class="layui-elem-field">
        <legend>筛选条件</legend>
        <div class="layui-field-box">
          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">客服名称</label>
            <div class="layui-input-inline">
              <input type="text" id="search_csname" placeholder="请输入客服名称" class="layui-input">
            </div>

            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
              <input type="text" id="search_gender" placeholder="请输入性别" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <div class="layui-inline">
              <button class="layui-btn layui-btn-radius layui-btn-warm" id="iReset">重置</button>
              <button class="layui-btn layui-btn-radius layui-btn-normal" id="searchVal">搜索</button>
            </div>
          </div>
        </div>
      </fieldset>


      <table class="layui-hide" id="test" lay-filter="test"></table>

      <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-sm" lay-event="insertCs">新增客服</button>
          <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
          <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
          <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        </div>
      </script>

      <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
      </script>


      <script type="text/html" id="insert_form">
        <div class="layui-field-box">
          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">客服名称</label>
            <div class="layui-input-inline">
              <input type="text" id="insert_csname" class="layui-input" placeholder="请输入客服名称">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
              <input type="text" id="insert_gender" class="layui-input" placeholder="请输入性别">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
              <input type="text" id="insert_age" class="layui-input" placeholder="请输入年龄">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <input type="text" id="insert_phone" class="layui-input" placeholder="请输入联系电话">
            </div>
          </div>

        </div>
      </script>

      <script type="text/html" id="update_form">
        <div class="layui-field-box">
          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">客服名称</label>
            <div class="layui-input-inline">
              <input type="text" id="update_csname" class="layui-input" placeholder="请输入客服名称">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
              <input type="text" id="update_gender" class="layui-input" placeholder="请输入性别">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
              <input type="text" id="update_age" class="layui-input" placeholder="请输入年龄">
            </div>
          </div>

          <div class="layui-form-item layui-form-pane">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <input type="text" id="update_phone" class="layui-input" placeholder="请输入联系电话">
            </div>
          </div>

        </div>
      </script>


    </div>
  </div>

  <div class="layui-footer">
    <!-- 底部固定区域 -->
       <link href="">@CopyRight      网安局备案号00000000</link>
  </div>
</div>
<script src="layui/layui.js" ></script>
<script src="jquery/jquery-3.6.0.js" ></script>
  <script>

    let username = sessionStorage.getItem("username")
    console.log("index.html  username"+username)
    $("#show_username").text(username)

    $("#iReset").click(function (){
      $("#search_csname").val("")
      $("#search_gender").val("")
      let jsonObj={};
      tableflush(jsonObj);
    });

    $("#searchVal").click(function (){
      let csname = $("#search_csname").val();
      let gender = $("#search_gender").val();
      let jsonObj={};
      if(csname != null & csname !=''){
        jsonObj.csname = csname;
      }
      if(gender != null & gender !=''){
        jsonObj.gender = gender;
      }
      tableflush(jsonObj);
    })

    function tableflush(jsonObj) {

        layui.use('table', function () {
          var table = layui.table;
          table.render({
            elem: '#test'
            , url: 'cs/selectByPage'/*tpa=http://www.layui.com/test/table/demo1.json*/
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,where: jsonObj
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
              title: '提示'
              , layEvent: 'LAYTABLE_TIPS'
              , icon: 'layui-icon-tips'
            }]
            , title: '客服表'
            , cols: [[
              {type: 'checkbox', fixed: 'left'}
              , {field: 'id', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true}
              , {field: 'csname', title: '客服名称', width: 150}
              , {
                field: 'gender', title: '性别', width: 150, templet: function (res) {
                  return '<em>' + res.gender + '</em>'
                }
              }
              , {field: 'age', title: '年龄', width: 80}
              , {field: 'phone', title: '联系电话', width: 220}
              , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 250}

            ]]
            , page: true
          });

          table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
              case 'insertCs':
                layer.open({     // 弹出框处理  模态框
                  type: 1               // 模态框
                  , title: '新增客服' //不显示标题栏
                  , closeBtn: false
                  , area: ['500px', '500px']  // 宽和高
                  , shade: 0.5
                  , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                  , btn: ['新增', '取消']
                  , btnAlign: 'c'
                  , moveType: 1 //拖拽模式，0或者1
                  , content: $('#insert_form').html()         // 引入自定义表单
                  , btn1: function (index, layero) {            // 这个是新增按钮点击事件
                    // layer.msg("新增按钮执行");
                    let csname = $("#insert_csname").val();
                    let gender = $("#insert_gender").val();
                    let age = $("#insert_age").val();
                    let phone = $("#insert_phone").val();
                    $.ajax({
                      url: "/cs/insert",           // 请求路径
                      type: "post",                  // 请求的方式，不区分大小写
                      cache: false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                      contentType: "application/json;charset=utf-8", //数据格式为json
                      data: JSON.stringify({
                        csname: csname,
                        gender: gender,
                        age: age,
                        phone: description
                      }),
                      datatype: "json",        // 返回类型，text文本、html页面、json数据
                      success: function (response) {
                        console.log("返回: " + response);
                        if (response.code === 200) {
                          layer.msg("新增客服成功!");
                          layer.close(index);                         // 关闭当前窗口
                          tableflush();
                        }
                      },
                      error: function (response) {
                        console.log("出错返回: " + response);
                      }
                    });
                  }
                  , success: function (layero) {

                  }
                });
                break;
              case 'getCheckData':
                var data = checkStatus.data;
                layer.alert(JSON.stringify(data));
                break;
              case 'getCheckLength':
                var data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
                break;
              case 'isAll':
                layer.msg(checkStatus.isAll ? '全选' : '未全选');
                break;

                    //自定义头工具栏右侧图标 - 提示
              case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
                break;
            }
            ;
          });

          //监听行工具事件
          table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
              layer.confirm('真的删除行么', function(index){
                $.ajax({
                  url:"/cs/deleteById",           // 请求路径
                  type:"post",                  // 请求的方式，不区分大小写
                  cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                  data: {
                    id:data.id
                  },
                  datatype:"json",        // 返回类型，text文本、html页面、json数据
                  success:function(response){
                    console.log("返回: " + response);
                    if(response.code === 200) {
                      layer.msg("删除客服成功!");
                      layer.close(index);                         // 关闭当前窗口
                      tableflush();
                    }
                  },
                  error:function(response){
                    console.log("出错返回: " + response);
                  }
                });
              });
            } else if (obj.event === 'edit') {
              layer.open({     // 弹出框处理  模态框
                type: 1               // 模态框
                ,title: '更新客服' //不显示标题栏
                ,closeBtn: false
                ,area: ['500px','500px']  // 宽和高
                ,shade: 0.5
                ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                ,btn: ['更新', '取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: $('#update_form').html()         // 引入自定义表单
                ,btn1: function(index, layero){            // 这个是新增按钮点击事件
                  let csname = $("#update_csname").val();
                  let gender = $("#update_gender").val();
                  let age = $("#update_age").val();
                  let phone = $("#update_phone").val();
                  $.ajax({
                    url:"/cs/updateById",           // 请求路径
                    type:"post",                  // 请求的方式，不区分大小写
                    cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify({
                      csname:csname,
                      gender:gender,
                      age:age,
                      phone:phone,
                      id:data.id, //获取当前选择的id
                    }),
                    datatype:"json",        // 返回类型，text文本、html页面、json数据
                    success:function(response){
                      console.log("返回: " + response);
                      if(response.code === 200) {
                        layer.msg("更新客服成功!");
                        layer.close(index);                         // 关闭当前窗口
                        tableflush();
                      }
                    },
                    error:function(response){
                      console.log("出错返回: " + response);
                    }
                  });
                }
                ,success: function(layero){   // 当弹出框再还未弹出时，完成的初始化工作
                  $("#update_csname").val(data.csname);
                  $("#update_gender").val(data.gender);
                  $("#update_age").val(data.age);
                  $("#update_phone").val(data.phone);
                }
              });
            }
          });
        });

    }
    tableflush();
  </script>

</body>
</html>
